{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2756bd06-e8c5-4e04-b904-a33a15fa6061",
   "metadata": {},
   "source": [
    "### Multi-Output Text Classification\n",
    "\n",
    "+ Binary Classification: target has either 0 or 1\n",
    "+ Multi-Class: A classification problem consisting of more than two classes. \n",
    "+ Multi-Label: A target can have more than two labels at the same time\n",
    "+ Multi-output: A target where each sample has multiple classification/regression labels\n",
    "    - Multiclass-multioutput classification (also known as multitask classification) is a classification task which labels each sample with a set of non-binary properties. \n",
    "    - Both the number of properties and the number of classes per property is greater than 2.\n",
    "    \n",
    "\n",
    "### Libraries\n",
    "+ Scikit-Learn\n",
    "    - sklearn.multioutput\n",
    "+ Scikit-Multi-Learn\n",
    "+ Tensorflow\n",
    "+ Pytorch\n",
    "+ etc\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2c533e24-c599-49d1-962f-b39158c3c84f",
   "metadata": {
    "tags": []
   },
   "source": [
    "![](MultiOutputvsMulti-Label-JCharisTech.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "47ae5357-7e04-4e41-b404-4a231f854813",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load EDA Pkgs\n",
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "bc6f887b-80f3-4e38-a81b-b75413fc2480",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load Data Viz Pkgs\n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3e781679-6682-4a1b-be46-683bb494f963",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load ML Pkgs\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "from sklearn.tree import DecisionTreeClassifier\n",
    "from sklearn.neighbors import KNeighborsClassifier\n",
    "from sklearn.naive_bayes import MultinomialNB\n",
    "\n",
    "# Transformers\n",
    "from sklearn.feature_extraction.text import CountVectorizer,TfidfVectorizer\n",
    "# Others\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.pipeline import Pipeline\n",
    "from sklearn.metrics import accuracy_score,classification_report,confusion_matrix,plot_confusion_matrix\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "8f36c93b-f392-4cf5-b638-aef0a925ca93",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load Dataset\n",
    "df = pd.read_csv(\"data/netflix_titles_dataset.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "8dd0e153-4a7c-4390-924f-bbc862c61780",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>title</th>\n",
       "      <th>description</th>\n",
       "      <th>type</th>\n",
       "      <th>rating</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3%</td>\n",
       "      <td>In a future where the elite inhabit an island ...</td>\n",
       "      <td>TV Show</td>\n",
       "      <td>TV-MA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>7:19</td>\n",
       "      <td>After a devastating earthquake hits Mexico Cit...</td>\n",
       "      <td>Movie</td>\n",
       "      <td>TV-MA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>23:59</td>\n",
       "      <td>When an army recruit is found dead, his fellow...</td>\n",
       "      <td>Movie</td>\n",
       "      <td>R</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>9</td>\n",
       "      <td>In a postapocalyptic world, rag-doll robots hi...</td>\n",
       "      <td>Movie</td>\n",
       "      <td>PG-13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>21</td>\n",
       "      <td>A brilliant group of students become card-coun...</td>\n",
       "      <td>Movie</td>\n",
       "      <td>PG-13</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Unnamed: 0  title                                        description  \\\n",
       "0           0     3%  In a future where the elite inhabit an island ...   \n",
       "1           1   7:19  After a devastating earthquake hits Mexico Cit...   \n",
       "2           2  23:59  When an army recruit is found dead, his fellow...   \n",
       "3           3      9  In a postapocalyptic world, rag-doll robots hi...   \n",
       "4           4     21  A brilliant group of students become card-coun...   \n",
       "\n",
       "      type rating  \n",
       "0  TV Show  TV-MA  \n",
       "1    Movie  TV-MA  \n",
       "2    Movie      R  \n",
       "3    Movie  PG-13  \n",
       "4    Movie  PG-13  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "4add7146-90ff-47c8-8b98-71c0aae41b49",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Movie      4788\n",
       "TV Show    2143\n",
       "Name: type, dtype: int64"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Class 1/Target 1/Output 1 Distribution\n",
    "df['type'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "5a1ec918-6f27-47fe-a107-e989359db102",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:xlabel='type', ylabel='count'>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEJCAYAAABlmAtYAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAATD0lEQVR4nO3df6zd9X3f8ecLkxB3CQuUC6M2qVFqtQGa0nDlsbBuWUiHp6YxTUPrqBlOi+SOkaiRlqzQVQ3thBZpWbWQBRZrS7BpC3GbH7hRaYPc0TQZiXOd0jiGMLxAwYViQ9qFdJNXu+/9cT4OJ9fH93Nh95x77ft8SEff7/d9Pp/v+VzpyC9/f31OqgpJkuZyymIPQJK09BkWkqQuw0KS1GVYSJK6DAtJUpdhIUnqGmtYJHk0yZ4k9yeZabUzk9yT5OG2PGOo/Q1J9iV5KMkVQ/VL2n72Jbk5ScY5bknSd5rEkcU/qaqLq2q6bV8P7KyqtcDOtk2SC4CNwIXAeuCWJCtan1uBzcDa9lo/gXFLkppTF+EzNwCva+tbgXuBX2z1O6vqEPBIkn3AuiSPAqdX1X0ASbYBVwJ3z/UhZ511Vq1Zs2bhRy9JJ7Hdu3c/XVVTs+vjDosCPpOkgA9X1RbgnKp6EqCqnkxydmu7CvjCUN/9rfY3bX12fU5r1qxhZmZmAf4ESVo+kvzZqPq4w+KyqnqiBcI9Sb42R9tR1yFqjvqxO0g2MzhdxSte8YrnO1ZJ0nGM9ZpFVT3RlgeATwLrgKeSnAvQlgda8/3AeUPdVwNPtPrqEfVRn7elqqaranpq6pijKEnSCzS2sEjyd5K87Og68E+BrwI7gE2t2Sbgrra+A9iY5LQk5zO4kL2rnbJ6Nsml7S6oq4f6SJImYJynoc4BPtnucj0V+K2q+v0kXwK2J7kGeAy4CqCq9ibZDjwAHAauq6ojbV/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B08QXA1clmU7yKgYT4V3W+h9pbaQlw+k+pAVWVX+U5ENJzgbeDHy8qg4nAbjn6NxFST7BYCbVwwxm+v1Sa7MSOLAog5eOw7CQxuN2BkcHG4GfG6rPnl+nGMymurWqbpjQ2KTnzdNQ0sJ4FnjZ0PZtwLsAqmrvUP1H2y++rWQwnfbngZ3AW9qRyNFfhPveCYxZmjePLKQFUFXPJPl8kq8Cd1fVe5I8yOA3RIZ9jsFRx/cBv1VVMwBtNtTPJDkF+BvgOvpTw0sT46yz0hgk+S5gD/CaqvpfrfZ2YLqq3rGYY5NeCE9DSQssyRuArwEfPBoU0onOIwtJUpdHFpKkLsNCktRlWEiSugwLSVKXYSFJ6jIsJEld/w9C6wh7dG0UjwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.countplot(x='type',data=df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "d4658abf-e4fb-4a08-9143-56c3f9b09f8c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "TV-MA    2863\n",
       "TV-14    1931\n",
       "TV-PG     806\n",
       "R         665\n",
       "PG-13     386\n",
       "TV-Y      280\n",
       "Name: rating, dtype: int64"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Class 2/Target 2/Output 2 Distribution\n",
    "df['rating'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "1d42d83f-3a42-4f04-b137-33d84c934d74",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:xlabel='rating', ylabel='count'>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEKCAYAAADjDHn2AAAAOXRFWHR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/BVerfGXjHA/Pe2O4hC7waUJ7bjGU+rqi+1+gfnsF9pv3gjQenA/BD+/kaDvw08v6q+m+Qqel+S1OXxvuHdwOH0vt1PmlfcspDmxpH0guP7SY6j9+VLezwKPG3QBVXVd4FHk5zRSgvq5o16cnLLQpoDVXVHkq/S+/6Eb9L7Ap49rgRuTLJzH8ctpvNa4D1Jfkjv+8C/P5f9SrPlqbPSPJTkqVX1WBu+BFhSVW8cc1taxNyykOanf53kUnq/o9+i9+1u0ti4ZSFJ6uQBbklSJ8NCktTJsJAkdTIsJEmdDAtJUifDQpLU6f8BeZht15ZbhDIAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.countplot(x='rating',data=df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "81df5a32-44e9-4ac1-9181-1c248f5a1adf",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load Pkgs\n",
    "from sklearn.multioutput import MultiOutputClassifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "ff725b37-e4f3-45df-aec4-5cdb0ee4a03e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Text Cleaning\n",
    "import neattext.functions as nfx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "bf38ada8-e881-4f5b-af45-7289989dd15a",
   "metadata": {},
   "outputs": [],
   "source": [
    "df['title'] = df['title'].str.lower()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "5f9dcab7-0788-455d-bb9c-fe1e3b02aaa2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>title</th>\n",
       "      <th>description</th>\n",
       "      <th>type</th>\n",
       "      <th>rating</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3%</td>\n",
       "      <td>In a future where the elite inhabit an island ...</td>\n",
       "      <td>TV Show</td>\n",
       "      <td>TV-MA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>7:19</td>\n",
       "      <td>After a devastating earthquake hits Mexico Cit...</td>\n",
       "      <td>Movie</td>\n",
       "      <td>TV-MA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>23:59</td>\n",
       "      <td>When an army recruit is found dead, his fellow...</td>\n",
       "      <td>Movie</td>\n",
       "      <td>R</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>9</td>\n",
       "      <td>In a postapocalyptic world, rag-doll robots hi...</td>\n",
       "      <td>Movie</td>\n",
       "      <td>PG-13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>21</td>\n",
       "      <td>A brilliant group of students become card-coun...</td>\n",
       "      <td>Movie</td>\n",
       "      <td>PG-13</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Unnamed: 0  title                                        description  \\\n",
       "0           0     3%  In a future where the elite inhabit an island ...   \n",
       "1           1   7:19  After a devastating earthquake hits Mexico Cit...   \n",
       "2           2  23:59  When an army recruit is found dead, his fellow...   \n",
       "3           3      9  In a postapocalyptic world, rag-doll robots hi...   \n",
       "4           4     21  A brilliant group of students become card-coun...   \n",
       "\n",
       "      type rating  \n",
       "0  TV Show  TV-MA  \n",
       "1    Movie  TV-MA  \n",
       "2    Movie      R  \n",
       "3    Movie  PG-13  \n",
       "4    Movie  PG-13  "
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "9f50003d-c48b-4721-b2b1-ba37528212d4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Features & Labels\n",
    "Xfeatures = df['title']\n",
    "ylabels = df[['type','rating']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "542b9718-3ada-48c8-b101-c5fa96747a07",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Split Data\n",
    "x_train,x_test,y_train,y_test = train_test_split(Xfeatures,ylabels,test_size=0.3,random_state=7)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2710b3ed-e148-4fe7-9cee-a20acf3dacec",
   "metadata": {},
   "source": [
    "### Build A Pipeline for our Model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "73eebff4-2d43-4870-858a-94f2ccf2e415",
   "metadata": {},
   "outputs": [],
   "source": [
    "pipe_lr = Pipeline(steps=[('cv',CountVectorizer()),\n",
    "                          ('lr_multi',MultiOutputClassifier(LogisticRegression()))])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "c8256af7-f9e8-4877-b2bf-a33c83e01279",
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/lib/python3.9/dist-packages/sklearn/linear_model/_logistic.py:763: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
      "STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n",
      "\n",
      "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
      "    https://scikit-learn.org/stable/modules/preprocessing.html\n",
      "Please also refer to the documentation for alternative solver options:\n",
      "    https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n",
      "  n_iter_i = _check_optimize_result(\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Pipeline(steps=[('cv', CountVectorizer()),\n",
       "                ('lr_multi',\n",
       "                 MultiOutputClassifier(estimator=LogisticRegression()))])"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Fit on Dataset\n",
    "pipe_lr.fit(x_train,y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "1af3f762-fa06-496b-a97a-08c4b8fd93b5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.2639423076923077"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Accuracy Score\n",
    "pipe_lr.score(x_test,y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "52b920ce-d30d-48de-9b3d-82ef9ffed950",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the midnight sky\n",
      "Actual Prediction: type      Movie\n",
      "rating    PG-13\n",
      "Name: 5917, dtype: object\n"
     ]
    }
   ],
   "source": [
    "# Sample Prediction\n",
    "print(x_test.iloc[0])\n",
    "print(\"Actual Prediction:\",y_test.iloc[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "86c8a332-3a9e-4e1a-9b8f-13d79112afb2",
   "metadata": {},
   "outputs": [],
   "source": [
    "ex1 = x_test.iloc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "8f189502-d871-4fa7-bebc-0994c6d84784",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'the midnight sky'"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ex1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "ce7b25d7-86d4-427e-b23a-672af37da2b8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([['Movie', 'TV-MA']], dtype=object)"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pipe_lr.predict([ex1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "72703365-dcf2-4375-a297-28b4f44ddb15",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[array(['Movie', 'TV Show'], dtype=object), array(['PG-13', 'R', 'TV-14', 'TV-MA', 'TV-PG', 'TV-Y'], dtype=object)]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[array([[0.74445483, 0.25554517]]),\n",
       " array([[0.12310188, 0.07038494, 0.21476461, 0.46916205, 0.10270243,\n",
       "         0.01988409]])]"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Prediction Prob\n",
    "print(pipe_lr.classes_)\n",
    "pipe_lr.predict_proba([ex1])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7f32da27-f606-45c5-94e8-48efba8d0569",
   "metadata": {},
   "source": [
    "#### Using ML Estimators that support multi-output\n",
    "+ KNN\n",
    "+ RF\n",
    "+ DT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "94ea7d44-fff2-49dd-98d4-9e579d186aa4",
   "metadata": {},
   "outputs": [],
   "source": [
    "pipe_knn = Pipeline(steps=[('cv',CountVectorizer()),('knn',KNeighborsClassifier(n_neighbors=4))])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "c30e292f-9f34-45ca-a0ca-7adbb1e26eea",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Pipeline(steps=[('cv', CountVectorizer()),\n",
       "                ('knn', KNeighborsClassifier(n_neighbors=4))])"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pipe_knn.fit(x_train,y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "972d2cfe-8600-41c7-8fe1-1071732d37df",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([['Movie', 'TV-MA']], dtype=object)"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pipe_knn.predict([ex1])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3a03b393-a1b0-4e86-91d7-44622b4a71bc",
   "metadata": {},
   "source": [
    "#### Narrative\n",
    "+ Difficult to compute accuracy using .score()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "4c490349-d43a-408f-b5ea-c6beb3e81d35",
   "metadata": {},
   "outputs": [],
   "source": [
    "#### Thanks For Watching\n",
    "#### Jesus Saves @JCharisTech\n",
    "#### Jesse E.Agbe(JCharis)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "47892c9f-4112-4f62-9770-1d90aed4ed0c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.1+"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
